package cn.ekuma.epos.kuaidi;

import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JButton;

//import net.miginfocom.swing.MigLayout;
import cn.ekuma.epos.datalogic.I_DataLogicSales;
import cn.ekuma.epos.db.table.kuaidi.I_KuaiDi;
import cn.ekuma.rabbit.spi.I_ModelPart;

import com.openbravo.bean.kuaidi.I_KuaiDiZhuangTai;
import com.openbravo.bean.kuaidi.KuaiDi;
import com.openbravo.beans.JStringDialog;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.query.QBFParameter;
import com.openbravo.pos.base.BeanFactoryApp;
import com.openbravo.pos.base.BeanFactoryException;
import com.openbravo.pos.base.I_AppView;
import com.openbravo.pos.forms.JPanelView;
import com.openbravo.pos.mode.POS_UI_Swing_Model;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Date;
import java.util.List;

public class JKuaiDiManagerPanel extends JPanel  implements JPanelView, BeanFactoryApp,I_ModelPart<POS_UI_Swing_Model>{
  
	private I_DataLogicSales dlSales;
	QBFParameter danhaoQBF,shouJiHaoQBF;
	/**
	 * Create the panel.
	 */
	public JKuaiDiManagerPanel() {
		//setLayout(new MigLayout("", "[132.00px][117px][117px][]", "[29px][29px][][63.00][][61.00]"));
		
		danhaoQBF=new QBFParameter(I_KuaiDi.DANHAO);
		shouJiHaoQBF=new QBFParameter(I_KuaiDi.DIANHUA);
		
		JButton btnNewButton = new JButton("代   收");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String code=JStringDialog.showEditText(JKuaiDiManagerPanel.this,"代收件", "请输入快递单号");
				if(code!=null&&!code.isEmpty()){
				  try {
					  List<KuaiDi> obj=(List<KuaiDi>) dlSales.queryByQBFParameter(KuaiDi.class, danhaoQBF.equal(code));
					  if(obj.isEmpty()){
						  KuaiDi newObj=new KuaiDi(code);
					      newObj.setZhuangTai(I_KuaiDiZhuangTai.DAISHOUJIAN);
					      newObj.setCreateTime(new Date());
					      dlSales.insert(newObj);
					     }
						  
				     } catch (BasicException e1) {
					   // TODO Auto-generated catch block
					   e1.printStackTrace();
				   }
				}
			}
		});
		btnNewButton.setBounds(113, 0, 112, 300);
		add(btnNewButton, "cell 0 2 1 2,grow");
		
		JButton btnNewButton_2 = new JButton("代   发");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		btnNewButton_2.setBounds(225, 0, 112, 300);
		add(btnNewButton_2, "cell 1 3,grow");
		
		JButton btnNewButton_3 = new JButton("取  件");
		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		btnNewButton_3.setBounds(337, 0, 112, 300);
		add(btnNewButton_3, "cell 2 3,grow");
		
				JButton btnNewButton_1 = new JButton("       查  件     ");
				btnNewButton_1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
					}
				});
				btnNewButton_1.setBounds(1, 0, 112, 300);
				add(btnNewButton_1, "cell 3 3,grow");
				
				JButton btnNewButton_4 = new JButton("代收退回");
				btnNewButton_4.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
					}
				});
				add(btnNewButton_4, "cell 0 5,grow");
				
				JButton btnNewButton_5 = new JButton("代发取消");
				btnNewButton_5.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
					}
				});
				add(btnNewButton_5, "cell 1 5,grow");

	}

	@Override
	public Object getBean() {
		return this;
	}

	@Override
	public String getModelName() {
		return POS_UI_Swing_Model.MODEL_NAME;
	}

	@Override
	public void setModel(POS_UI_Swing_Model mode) {
		dlSales = mode.getDLSales();
	}

	@Override
	public void init(I_AppView app) throws BeanFactoryException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String getTitle() {
		
		return "快递收发管理";
	}

	@Override
	public void activate() throws BasicException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean deactivate() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public JComponent getComponent() {
		return this;
	}

}
